const http = require("http");
const { readStatic } = require("./api/static");
const { login } = require("./api/user");

const server = http.createServer((req, res) => {
    console.log("req.url", req.url);
    console.log("req.method", req.method);

    switch (true) {
        case req.url === "/favicon.ico":
            req.url = "/files/imgs/fuckoff.jpg";
            readStatic(req, res);
            break;

        // 访问静态文件 /files/pages/login.html
        case req.url.startsWith("/files/"):
            // 将静态文件读入并通过res返回客户端
            readStatic(req, res);
            break;

        // 处理登录请求
        case req.url.startsWith("/login"):
            login(req, res);
            break;

        default:
            res.end("hello nodejs");
            break;
    }

    
});

server.listen(8001, () => console.log("server is running at 8001..."));
